package org.cmroot.certmaster.client.dialogs;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.*;

/**
 * Copyright (c) 2011 Andrey Domas <andrey.domas at gmail.com>.
 * *
 * This file is part of certmaster.
 * *
 * Certmaster is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * *
 * Certmaster is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see http://www.gnu.org/licenses
 * or write to the Free Software Foundation,Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301  USA
 */
public class ConfirmDialog extends Composite {

    interface DeleteDialogUiBinder extends UiBinder<Widget, ConfirmDialog> {}
    private static DeleteDialogUiBinder _deleteDialogUiBinder = GWT.create(DeleteDialogUiBinder.class);

    @UiField DialogBox dialogBox;
    @UiField PushButton confirmButton;
    @UiField PushButton cancelButton;
    @UiField Label questionLabel;

    public ConfirmDialog() {
        initWidget(_deleteDialogUiBinder.createAndBindUi(this));

        dialogBox.center();

        cancelButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                dialogBox.hide();
            }
        });

        confirmButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent clickEvent) {
                dialogBox.hide();
            }
        });
    }

    public void addConfirmHandler(ClickHandler handler) {
        confirmButton.addClickHandler(handler);
    }

    public void setQuestion(String s) {
        questionLabel.setText(s);
    }

    public void show() {
        dialogBox.show();
    }
}